package everyday.m20230309;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Q20230323 {

    public static void main(String[] args) {
        Q20230323 q20230323 = new Q20230323();
        System.out.println(q20230323.checkArithmeticSubarrays(new int[]{
                4,6,5,9,3,7
        }, new int[]{0,0,2}, new int[]{2,3,5}));
    }

    public List<Boolean> checkArithmeticSubarrays(int[] nums, int[] l, int[] r) {
        List<Boolean> result = new ArrayList<>();
        for (int i = 0; i < l.length; i++) {
            result.add(isArithmeticSubarrays(nums, l[i], r[i]));
        }
        return result;
    }

    private boolean isArithmeticSubarrays(int[] nums, int start, int end) {
        int[] checks = Arrays.copyOfRange(nums, start, end + 1);
        Arrays.sort(checks);
        int s = checks[1] - checks[0];
        for (int i = 0; i < end - start; i++) {
            if (checks[i + 1] - checks[i] != s) {
                return false;
            }
        }
        return true;
    }
}
